package com.neo.springcloud.service.impl;

import com.neo.springcloud.service.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @ClassName: MessageProviderImpl
 * @Title: cloud2021
 * @Package: com.neo.springcloud.service.impl
 * @Description:
 * @Author: Kisen
 * @Date: 2021/10/6 15:29
 */
@EnableBinding(Source.class) // 定义消息的推送管道
public class MessageProviderImpl implements IMessageProvider {

    @Resource
    private MessageChannel output; // 消息发送管道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        System.out.println(serial + "======");
        output.send(MessageBuilder.withPayload(serial).build());
        return serial;
    }
}
